package com.heatup.apt.api.controller;

import com.heatup.apt.api.service.HotRecomService;
import com.heatup.apt.common.util.JsonTools;
import com.heatup.apt.common.util.PageBean;
import com.heatup.apt.common.util.RequestTools;
import com.heatup.apt.common.util.ResponseTools;
import com.heatup.apt.model.api.ApiResultModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 热门推荐 
 * <P>File name : HotRecomController.java </P>
 * <P>Author : fangxiaowen </P> 
 * <P>Date : 2016年8月22日 </P>
 */
@RequestMapping(value = "/hot/recom")
@Controller
public class HotRecomController extends BaseController{
	private Logger logger = LoggerFactory.getLogger(HotRecomController.class);
    @Resource
    private HotRecomService hotRecomService;
    
    /**
     * 本周热门课程
     * HotRecomController.hot_course()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年8月26日 </P>
     * @param request
     * @param page
     * @return
     */
    @RequestMapping(value = "/hot_banner", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String hot_banner(HttpServletRequest request,PageBean page) {
    	String callback=RequestTools.RequestString(request, "callback", "");
    	ApiResultModel apiResultModel = new ApiResultModel();
        try {
        	apiResultModel = hotRecomService.getHotBannerList(page);
		} catch (Exception e) {
			e.printStackTrace();
	        apiResultModel.setRet(ApiResultModel.RET_ERROR);
	        apiResultModel.setMsg("");
	        logger.error("hot_banner error:",e);
		}
        apiResultModel.setLogined(isLogined());
    	return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
    }
    
    /**
     * 热门推荐教练视频
     * HotRecomController.hot_list()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年8月22日 </P>
     * @param request
     * @param page
     * @return
     */
    @RequestMapping(value = "/hot_coach_list", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String hot_list(HttpServletRequest request,PageBean page) {
        String callback=RequestTools.RequestString(request, "callback", "");
        ApiResultModel apiResultModel = new ApiResultModel();
        try {
        	apiResultModel = hotRecomService.getHotCoachList(page);
		} catch (Exception e) {
			e.printStackTrace();
	        apiResultModel.setRet(ApiResultModel.RET_ERROR);
	        apiResultModel.setMsg("运行时异常："+e.getMessage());
	        logger.error("hot_list error:",e);
		}
        apiResultModel.setLogined(isLogined());
        return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
    }
    
    /**
     * 最受欢迎的团体课
     * HotRecomController.mostpop_course_list()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年8月23日 </P>
     * @param request
     * @param page
     * @return
     */
    @RequestMapping(value = "/mostpop_course_list", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String mostpop_course_list(HttpServletRequest request,PageBean page) {
    	String callback=RequestTools.RequestString(request, "callback", "");
    	ApiResultModel apiResultModel = new ApiResultModel();
    	try {
    		apiResultModel = hotRecomService.getMostpopCourseList(page);
		} catch (Exception e) {
			e.printStackTrace();
	        apiResultModel.setRet(ApiResultModel.RET_ERROR);
	        apiResultModel.setMsg("");
	        logger.error("mostpop_course_list error:",e);
		}
    	apiResultModel.setLogined(isLogined());
    	return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
    }
    
    /**
     * 热门文章
     * HotRecomController.hotart_list()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年8月23日 </P>
     * @param request
     * @param page
     * @return
     */
    @RequestMapping(value = "/hotart_list", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String hotart_list(HttpServletRequest request,PageBean page) {
    	String callback=RequestTools.RequestString(request, "callback", "");
    	ApiResultModel apiResultModel = new ApiResultModel();
        try {
        	apiResultModel = hotRecomService.getHotartList(page);
		} catch (Exception e) {
			e.printStackTrace();
	        apiResultModel.setRet(ApiResultModel.RET_ERROR);
	        apiResultModel.setMsg("运行时异常:"+e.getMessage());
	        logger.error("hotart_list error:",e);
		}
        apiResultModel.setLogined(isLogined());
    	return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
    }
    
    /**
     * 热门tab
     * HotRecomController.hot_main_info()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年8月29日 </P>
     * @param request
     * @return
     */
    @RequestMapping(value = "/hot_main_info", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String hot_main_info(HttpServletRequest request) {
    	String callback=RequestTools.RequestString(request, "callback", "");
    	ApiResultModel apiResultModel = new ApiResultModel();
    	try {
    		apiResultModel = hotRecomService.getHotMainInfo();
		} catch (Exception e) {
			e.printStackTrace();
	        apiResultModel.setRet(ApiResultModel.RET_ERROR);
	        apiResultModel.setMsg("运行时异常:"+e.getMessage());
	        logger.error("hot_main_info error:",e);
		}
    	apiResultModel.setLogined(isLogined());
    	return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
    }
    
    
    
}